/*
superSonic.h
offer super sonic sensor function api ,data type define 
designed by lunanting

------------------------------
2020-04-10 13:26:48
create file
------------------------------
*/
#ifndef __SUPERS_H
#define __SUPERS_H
#include "base_type.h"
#include "aos/kernel.h"
#include "aos/hal/uart.h"

//sensor type
#define SuperS_type 2500

#define UART_wait 500

/**********************date type define*********************/
//sensor type
typedef enum{
    supers_dis=1,   //面对刷面左边，顺时针数第一个，预留测量车距
    supers_f1,      //前进行车避障1
    supers_f2,      //前进行车避障2
    supers_b1,      //后退行车避障1
    supers_b2,      //后退行车避障2
    supers_end      //检测车面结束
}SUPERS_sensor;

//sensor mesure type
typedef enum{
    supers_A=0,     //A测量协议
    supers_B,       //B测量协议
    supers_C        //C测量协议
}SUPERS_ABC;

//sensor state
typedef struct{
    u8 online;   //sensor online state,1=online
    u16 dis;    //distance :cm
    u8 error;     //error,0=no fault,1=fault
}SUPERS_state;

//super sonic handler
typedef struct{
    u8 init;    //init state,0=uninit,1=init
    aos_sem_t sem;  //thread lock sem
    SUPERS_state state[8]; //sensor state
    uart_dev_t uart;    //uart handdler
}SUPERS_handler;

/******************extern function***********************/

extern int xp_supers_init(u8 port,u32 speed);   //init super sonic sensor
extern int xp_supers_set_addr(u8 addr1,u8 addr2);   //change supersonic sensor address from add1 to addr2
extern u8 xp_supers_online_check(u8 addr);  //check sensor online state
extern u8 xp_supers_get_onlyone_addr(void); //read sensor address only one online
extern int xp_supers_factory_set(u8 addr); //factory setting sensor
extern u8 xp_supers_get_temperature(u8 addr);   //get sensor temperature
extern int xp_supers_get_dis(u8 addr,SUPERS_ABC type,u8 cycle); //get distance from supersonic sensor

extern u8 xp_supers_ask_checksum(u8 *data,u8 len);  //supersonic sensor ask checksum
extern int xp_supers_response_checksum(u8 *data);   //supersonic sensor response checksum



extern void xp_supers_test(void);   //test spuersonic sensor mesure distance
extern int xp_supers_debug(char *type,char *fun,char *param);   //cli debug
#endif
//end of the file
